package com.AUI
{
	import com.AUI.define.style.*;
	import flash.utils.*;
	import flash.display.*;
	import flash.geom.*;
	/**
	 * Cascading style sheets.
	 * @author HuangMinPing
	 * @site www.AminLab.com
	 */
	public class ACss
	{
		/**
		 * Selector.
		 */
		public var selectors:Object = new Object;
		/**
		 * Add a style.
		 */
		public function addStyle(name:String,attrs:Vector.<ACssStyleAttr>):void
		{
			var fname:String = name.toLowerCase();
			var cur:Vector.<ACssStyleAttr> = selectors[fname] || (new Vector.<ACssStyleAttr>);
			cur = cur.concat(attrs);
			selectors[fname] = cur;
		}
		/**
		 * Get a type selector by name.
		 */
		public function getStyle(name:String):Vector.<ACssStyleAttr>
		{
			var fname:String = name.toLowerCase();
			return selectors[fname];
		}
		/**
		 * Image library.
		 */
		static private var _img:Dictionary = new Dictionary;
		/**
		 * Get or set a image.
		 */
		static public function setImage(name:String,value:*):void
		{
			_img[name] = value;
		}
		static public function getImage(id:String):*
		{
			var image:BitmapData = _img[id];
			if(image != null)
			{
				return image;
			}
			var array:Array = id.split(' ');
			var name:String = array[0];
			var clipX:int = parseInt(array[1]);
			var clipY:int = parseInt(array[2]);
			var clipW:int = parseInt(array[3]);
			var clipH:int = parseInt(array[4]);
			image = _img[name];
			var newIamge:BitmapData = new BitmapData(clipW,clipH,true,0x00000000);
			newIamge.copyPixels(image,new Rectangle(clipX,clipY,clipW,clipH),new Point(0,0));
			_img[id] = newIamge;
			return newIamge;
		}
		static public function addEmbedImages(...arg:Array):void
		{
			for(var i:int = 0,len:int = arg.length;i < len;i += 2)
			{
				setImage(arg[i],Bitmap(new (arg[i + 1])).bitmapData);
			}
		}
	}
}